package com.neuedu.yyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.common.CommonResult;
import com.neuedu.yyzx.entity.NurseLevel;
import com.neuedu.yyzx.service.INurseLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 护理级别 前端控制器
 * </p>
 *
 * @author dya
 * @since 2021-04-27
 */
@RestController
@RequestMapping("//nurseLevel")
public class NurseLevelController {
    @Autowired
    INurseLevelService nurseLevelService;

    @RequestMapping("/list")
    CommonResult list(Page page, NurseLevel nurseLevel){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_deleted",0);
        if(nurseLevel!= null && StringUtils.isNotEmpty(nurseLevel.getLevelName())){
            queryWrapper.like("level_name",nurseLevel.getLevelName());
        }
        return CommonResult.success(nurseLevelService.page(page,queryWrapper)) ;
    }

    @RequestMapping("/add")
    CommonResult add(NurseLevel nurseLevel){
        return CommonResult.success( nurseLevelService.saveOrUpdate(nurseLevel));
    }

    @RequestMapping("/getById")
    CommonResult getById(Integer id){

        return CommonResult.success(nurseLevelService.getById(id));
    }

    @RequestMapping("/del")
    CommonResult del(Integer id){
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.set("is_deleted",1);
        updateWrapper.eq("id",id);

        return CommonResult.success(nurseLevelService.update(updateWrapper));
    }

}
